package com.icow.wms.basic.domain;

import com.alibaba.fastjson.JSON;
import com.icow.wms.basic.utils.HttpClientUtils;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.Date;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Slf4j
public class WcsTaskState implements Runnable {
    private String url;
    private String token;
    private String json;

    @Override
    public void run() {
        int count = 10;
        while (true) {
            try {
                count--;
                if (count < 0) {
                    log.info("The number of task status reports has reached the upper limit 10 times");
                    return;
                }
                Thread.sleep(1000);
                log.info("Task status reporting " + json);
                if (token != null && !token.equals("")) {
                    String stateResponseJson = HttpClientUtils.sendPostWithToken(url, json, token);
                    log.info("Task status reply " + stateResponseJson);
                    return;
                } else {
                    String stateResponseJson = HttpClientUtils.sendPost(url, json);
                    log.info("Task status reply " + stateResponseJson);
                    return;
                }
            } catch (Exception e) {
                log.info("Report abnormal WMS data " + e.getMessage());
            }

        }
    }
}
